﻿
/// <reference path="../Core.js" />

//所有面版盒子基类
IM.Control.Panel = function(conf) {
    IM.Control.ControlBase.apply(this, arguments);
    this.Render; //渲染目标

    this.Container; //包含当前面版的容器

    this.SetWidth = function(width) { if (typeof this.Render == "object") this.Render.css("width", width); };
    this.SetHeight = function(height) { if (typeof this.Render == "object") this.Render.css("height", height); };
    this.SetTop = function(top) { if (typeof this.Render == "object") this.Render.css("top", top); };
    this.SetLeft = function(left) { if (typeof this.Render == "object") this.Render.css("left", left); };

    this.SetZIndex = function(zindex) { if (typeof this.Render == "object") this.Render.css("z-index", zindex); };

    //设置css position属性
    this.SetPosition = function(position) {
        if (typeof this.Render != "object")
            return;
        if (typeof position != "string")
            return;
        if (position == "static" || position == "absolute" || position == "fixed" || position == "relative") {
            this.Render.css("position", position);
        }
    };

    this.GetWidth = function() { if (typeof this.Render == "object") return this.Render.width(); return 0; };
    this.GetHeight = function() { if (typeof this.Render == "object") return this.Render.height(); return 0; };
    this.GetTop = function() { if (typeof this.Render == "object") return this.Render.offset().top; return 0; };
    this.GetLeft = function() { if (typeof this.Render == "object") return this.Render.offset().left; return 0; };
    this.GetZIndex = function() { if (typeof this.Render == "object") return this.Render.css("z-index"); return -1; };
    this.GetPosition = function() {
        if (typeof this.Render == "object")
            return this.Render.css("position");
    };

    this.Css = function(name, value) {
        if (typeof this.Render == "object")
            return this.Render.css(name, value);
    };

    //选择器 select 为选择器或jquery对象或html元素
    this.SetRender = function(select) {
        if (typeof select == "undefined") {
            if (typeof this.Render == "undefined" || this.Render == null) {//如果Render未定义则退出
                this.Render = $("<div></div>"); //创建当前面版Render渲染对象
                this.Render.addClass("IM_NewPanelDefault");
                if (typeof this.Container == "undefined") {//如果当前容器为空,设置body为当前容器
                    this.Container = $(document.body);
                }

                if (typeof this.Container.append != "undefined")
                    this.Container.append(this.Render);
                return;
            }
            else if (typeof this.Render == "string") {//如果传的是字符串id则用jquery获取对象
                this.Render = $("#" + this.Render);
                this.Container = this.Render.parent();
            }
            else {
                this.Render = $(this.Render);
                this.Container = this.Render.parent();
            }
        }
        else {
            this.Render = $(select);
            this.Container = this.Render.parent();
        }

    };

    this.PanelInit = function() {
        //设置选择器
        this.SetRender();
    };
    this.PanelInit();
};